package com.zzuli.practice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zzuli.practice.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper extends BaseMapper<User> {

    User selectByName(String username);

    //映射
    @Results(id="userinfoMaps", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "username"),
            @Result(property = "gender", column = "gender"),
            @Result(property = "address", column = "address"),
            @Result(property = "phone", column = "phone")
    })
    @Select("<script>" +
            "select id, username, gender, address, phone from user " +
            "<where>" +
            "<if test='keyword !=null'>" +
            " username like CONCAT('%',#{keyword},'%') or " +
            " gender like CONCAT('%',#{keyword},'%') or " +
            " address like CONCAT('%',#{keyword},'%') or " +
            " phone like CONCAT('%',#{keyword},'%') " +
            "</if>" +
            "</where>"+
            " limit #{pageIndex},#{pageSize}" +
            "</script>")
    public List<User> getUserinfoPage(@Param("pageIndex") Integer pageIndex, @Param("pageSize") Integer pageSize, @Param("keyword") String keyword);

    @Select("<script>" +
            "select Count(*) from user " +
            "<where>" +
            "<if test='keyword != null'>" +
            " username like CONCAT('%',#{keyword},'%') or" +
            " gender like CONCAT('%',#{keyword},'%') or " +
            " address like CONCAT('%',#{keyword},'%') or " +
            " phone like CONCAT('%',#{keyword},'%') " +
            "</if>" +
            "</where>" +
            "</script>")
    public Integer getTotal(@Param("keyword") String keyword);

}
